<template>
  <ContentWrap v-loading="formLoading">
    <el-form
ref="formRef" :model="formData" :rules="formRules" label-width="100px" :disabled="true"
      v-loading="formLoading">
      <el-form-item label="类型" prop="infoType">
        <el-select v-model="formData.infoType" placeholder="请选择类型">
          <el-option
v-for="dict in getIntDictOptions(DICT_TYPE.WINE_MARKET)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="信息名称" prop="infoNme">
        <el-input v-model="formData.infoNme" placeholder="请输入信息名称" />
      </el-form-item>
      <el-form-item label="简短标题" prop="infoTitle">
        <el-input v-model="formData.infoTitle" placeholder="请输入简短标题" />
      </el-form-item>
      <el-form-item label="年份" prop="showYear">
        <el-date-picker value-format="YYYY" format="YYYY" v-model="formData.showYear" type="year" placeholder="请选择年份" />
      </el-form-item>
      <el-form-item label="香型" prop="fragranceType">
        <el-select v-model="formData.fragranceType" placeholder="请选择香型">
          <el-option
v-for="dict in getIntDictOptions(DICT_TYPE.ODOR_TYPE)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="均价" prop="averagePrice">
        <el-input-number v-model="formData.averagePrice" placeholder="请输入均价" />
      </el-form-item>
      <el-form-item label="涨幅量" prop="salePrice">
        <el-input-number v-model="formData.salePrice" placeholder="请输入涨幅量" />
      </el-form-item>
      <el-form-item label="描述" prop="description">
        <Editor v-model="formData.description" height="150px" />
      </el-form-item>
      <el-form-item label="价格状态" prop="status">
        <el-radio-group v-model="formData.status">
          <el-radio v-for="dict in getIntDictOptions(DICT_TYPE.PRICE_STATE)" :key="dict.value" :label="dict.value"> {{
    dict.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="formData.sort" placeholder="请输入排序" />
      </el-form-item>
      <el-form-item label="是否置顶" prop="isTop">
        <el-radio-group v-model="formData.isTop">
          <el-radio :key="dict.value" :label="dict.value" v-for="dict in getIntDictOptions(DICT_TYPE.IS_NO)">{{
    dict.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="统计时间" prop="countTime">
        <el-date-picker v-model="formData.countTime" type="date" value-format="x" placeholder="选择统计时间" />
      </el-form-item>
    </el-form>
    <el-form>
      <el-form-item style="float: right">
        <!-- <el-button  :loading="formLoading" type="primary" @click="submitForm">
          保存
        </el-button> -->
        <el-button @click="close">返回</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>
</template>
<script setup lang="ts">
import { SupplyMarketApi, SupplyMarketVO } from '@/api/wine/supplymarket'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { useTagsViewStore } from '@/store/modules/tagsView'

/** 酒类行情管理 表单 */
defineOptions({ name: 'SupplyMarketForm' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const { params } = useRoute() // 查询参数
const { delView } = useTagsViewStore() // 视图操作
const { push, currentRoute } = useRouter() // 路由


const formData = ref({
  id: undefined,
  infoType: undefined,
  infoNme: undefined,
  infoTitle: undefined,
  showYear: undefined,
  fragranceType: undefined,
  averagePrice: undefined,
  salePrice: undefined,
  description: undefined,
  status: undefined,
  sort: undefined,
  isTop: undefined,
  countTime: undefined
})
const formRules = reactive({
})
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const getDetail = async () => {
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      formData.value = await SupplyMarketApi.getSupplyMarket(id)
      if (!formData.value.description) {
        formData.value.description = ''
      }
    } finally {
      formLoading.value = false
    }
  }
}

onMounted(async () => {
  await getDetail()
})
const id = params.id as unknown as number
const formLoading = ref(false)

// /** 提交表单 */
// const submitForm = async () => {
//   // 校验表单
//   await formRef.value.validate()
//   // 提交请求
//   formLoading.value = true
//   try {
//     const data = formData.value as unknown as SupplyMarketVO
//     if (!id) {
//       await SupplyMarketApi.createSupplyMarket(data)
//       message.success(t('common.createSuccess'))
//     } else {
//       await SupplyMarketApi.updateSupplyMarket(data)
//       message.success(t('common.updateSuccess'))
//     }
//     close()
//   } finally {
//     formLoading.value = false
//   }
// }
const close = () => {
  delView(unref(currentRoute))
  push({ name: 'SupplyMarket' })
}
// /** 重置表单 */
// const resetForm = () => {
//   formData.value = {
//     id: undefined,
//     infoType: undefined,
//     infoNme: undefined,
//     infoTitle: undefined,
//     showYear: undefined,
//     fragranceType: undefined,
//     averagePrice: undefined,
//     salePrice: undefined,
//     description: undefined,
//     status: undefined,
//     sort: undefined,
//     isTop: undefined,
//     countTime: undefined
//   }
//   formRef.value?.resetFields()
// }
</script>